//
//  HZFocusDoctorViewController.m
//  MyDoctor
//
//  Created by 黑眼圈 on 16/5/5.
//  Copyright © 2016年 heiyan. All rights reserved.
//关注医生

#import "HZFocusDoctorViewController.h"
#import "HZFocusDoctorCell.h"
#import "HZFocusDoctorModel.h"

@interface HZFocusDoctorViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) NSArray *dataArray;

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation HZFocusDoctorViewController

#pragma mark -
#pragma mark 懒加载数组
//- (NSArray *)dataArray {
//    if (nil == _dataArray) {
//        _dataArray = [NSArray array];
//    }
//    return _dataArray;
//}

- (void)setDataArray:(NSArray *)dataArray {
    _dataArray = dataArray;
    [self.tableView reloadData];
}

- (void)loadView {
    
    UITableView *tableView = [[UITableView alloc] init];
    self.view = tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置并添加子控件
    [self setupUI];
    
    
}


#pragma mark -
#pragma mark    设置并添加子控件
-(void)setupUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    self.tableView = (UITableView *)self.view;
    //注册cell
    [self.tableView registerClass:[HZFocusDoctorCell class] forCellReuseIdentifier:@"focusDoctorCell"];
    
    
    //设置数据源及代理
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    
    self.tableView.rowHeight = 100;
    
    [self upData];
}

- (void)upData {
    
    NSString *urlString = @"http://iosapi.itcast.cn/matchDoctors.json.php";
    
//    NSDictionary *parameters = @{@"user_id":@1000089,@"doctor_id":@300000315};
    NSDictionary *parameters = @{@"ci1_id":@1,@"ci2_id":@3,@"ci3_id":@3,@"diagnosis_type":@0,@"page_size":@15,@"is_confirmed":@1,@"user_id":@1000089, @"page":@1,@"has_diagnosis":@2};
    
    [[HZNetTools sharedTools] postRequest:urlString parameters:parameters finishedBlock:^(id responstObject, NSError *error) {
        
        if (error != nil) {
            NSLog(@"请求失败");
            return;
        }
        
//        NSLog(@"%@",responstObject);
        NSDictionary *res = responstObject;
        
        NSArray *dicts = res[@"data"];
        
        NSMutableArray *tempArray = [NSMutableArray array];
        
        for (NSDictionary *dict in dicts) {
            //字典转模型
            HZFocusDoctorModel *model = [HZFocusDoctorModel focusDoctorModelWithDict:dict];
            
            [tempArray addObject:model];
        }
        
        self.dataArray = tempArray;
        
    }];
}



#pragma mark -
#pragma mark tableView数据源代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HZFocusDoctorCell *cell = [tableView dequeueReusableCellWithIdentifier:@"focusDoctorCell" forIndexPath:indexPath];
    
    cell.focusDoctorModel = self.dataArray[indexPath.item];
    
    return cell;
}








@end
